/**
 * User handler
 */
User = function() {
    
};

User.prototype.processLogin = function() {
    var username = $.trim($('#txtUsername').val());
    var password = $.trim($('#txtPassword').val());
    if (username == '') {
        $("#loginErr").show();
        $("#loginErr .error_msg").html("Please input username.");
        return false;
    }
    if (password == '') {
        $("#loginErr").show();
        $("#loginErr .error_msg").html("Please input password.");
        return false;
    }
    $("#loginErr").hide();
    $(".loading_22").show();
    $.ajax({
        type: 'POST',
        url: "/",
        data: {username: username, password: password, c:"ajax", a:"login"},
        success: function(response) {
            $(".loading_22").hide();
            if (response != "Ok") {
                $("#loginErr").show();
                $("#loginErr .error_msg").html("Login fail.");
            } else {
                user.loadProfileBox();
            }
        },
        error: function() {
            alert('error');
        }
    });
};

User.prototype.loadProfileBox = function() {
    $.ajax({
        type: 'GET',
        url: "/",
        data: {c:"ajax", a:"profileBox"},
        success: function(response) {
            $('#profile-box').html(response);
            $('#profile-box').removeClass('login');
        }
    });
};

user = new User();